package com.system.healthproject.model.sickuser.service.imp;

import com.system.healthproject.bean.web.ResultCard;
import com.system.healthproject.bean.web.ResultOrder;
import com.system.healthproject.bean.web.ResultPatientAccount;
import com.system.healthproject.bean.web.ResultSickuserAccountDetailed;
import com.system.healthproject.mapper.CardMapper;
import com.system.healthproject.mapper.CardOrderMapper;
import com.system.healthproject.mapper.PatientMapper;
import com.system.healthproject.model.sickuser.service.AccountInfoService;
import com.system.healthproject.pojo.CardOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AccountInfoServiceImpl implements AccountInfoService {
    @Autowired
    private PatientMapper patientMapper;
    @Autowired
    private CardMapper cardMapper;
    @Autowired
    private CardOrderMapper cardOrderMapper;

    /**
     * 查询患者账户信息
     * @param loginId
     * @return
     */
    @Override
    public ResultPatientAccount selectSickuserAccount(Integer loginId) {
        return patientMapper.selectSickuserAccount(loginId);
    }

    /**
     * 查看账户明细
     * @param loginId
     * @return
     */
    @Override
    public List<ResultSickuserAccountDetailed> selectSickuserAccountDetailed(Integer loginId) {
        return patientMapper.selectSickuserAccountDetailed(loginId);
    }

    @Override
    /**
     * 账户信息  充值卡
     */
    public List<ResultCard> selectCard() {
        return cardMapper.selectCard();
    }

    /**
     * 去充值  产生的订单
     * @param loginId
     * @param cardId
     * @return
     */
    @Override
    @Transactional
    public ResultOrder goRecharge(Integer loginId, Integer cardId) {
        CardOrder cardOrder = new CardOrder();
        cardOrder.setLoginId(loginId);
        cardOrder.setCardId(cardId);
        cardOrder.setCardorderStatue(1);
        cardOrderMapper.goRecharge(cardOrder);//添加订单
        Integer cardorderId =cardOrder.getCardorderId();//获取添加的订单ID
        //根据ID查询订单
        return cardOrderMapper.selectOrder(cardorderId);
    }
}
